<html>
 <head>
  <meta charset="utf-8"/>
  <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport"/>
  <title>
   k最近邻(KNN)分类法介绍，及Java算法实现  | 数螺 | NAUT IDEA
  </title>
  <link href="http://cdn.bootcss.com/bootstrap/3.3.6/css/bootstrap-theme.min.css" rel="stylesheet"/>
  <link href="http://cdn.bootcss.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
  <style type="text/css">
   #xmain img {
                  max-width: 100%;
                  display: block;
                  margin-top: 10px;
                  margin-bottom: 10px;
                }

                #xmain p {
                    line-height:150%;
                    font-size: 16px;
                    margin-top: 20px;
                }

                #xmain h2 {
                    font-size: 24px;
                }

                #xmain h3 {
                    font-size: 20px;
                }

                #xmain h4 {
                    font-size: 18px;
                }


                .header {
	           background-color: #0099ff;
	           color: #ffffff;
	           margin-bottom: 20px;
	        }

	        .header p {
                  margin: 0px;
                  padding: 10px 0;
                  display: inline-block;  
                  vertical-align: middle;
                  font-size: 16px;
               }

               .header a {
                 color: white;
               }

              .header img {
                 height: 25px;
              }
  </style>
  <script src="http://cdn.bootcss.com/jquery/3.0.0/jquery.min.js">
  </script>
  <script src="http://nautstatic-10007657.file.myqcloud.com/static/css/readability.min.js" type="text/javascript">
  </script>
  <script type="text/javascript">
   $(document).ready(function() {
                 var loc = document.location;
                 var uri = {
                  spec: "http://dataunion.org/16445.html",
                  host: "http://dataunion.org",
                  prePath: "http://dataunion.org",
                  scheme: "http",
                  pathBase: "http://dataunion.org/"
                 };
    
                 var documentClone = document.cloneNode(true);
                 var article = new Readability(uri, documentClone).parse();
     
                 document.getElementById("xmain").innerHTML = article.content;
                });
  </script>
  <!-- 1466461460: Accept with keywords: (title(0.4):算法,邻,社区,分类法,数盟, topn(0.5):社区,数据文件,队列,数盟,行业资讯,数值,数据挖掘,原理,标号,遍历,优先级,人工智能,职业规划,基础架构,随机数,文章,可视化,数据,度量,数据分析,计算,元组,算法,类别,编程语言,分类,误差率,距离,差值,属性).-->
 </head>
 <body onload="">
  <div class="header">
   <div class="container">
    <div class="row">
     <div class="col-xs-6 col-sm-6 text-left">
      <a href="/databee">
       <img src="http://nautidea-10007657.cos.myqcloud.com/logo_white.png"/>
      </a>
      <a href="/databee">
       <p>
        数螺
       </p>
      </a>
     </div>
     <div class="hidden-xs col-sm-6 text-right">
      <p>
       致力于数据科学的推广和知识传播
      </p>
     </div>
    </div>
   </div>
  </div>
  <div class="container text-center">
   <h1>
    k最近邻(KNN)分类法介绍，及Java算法实现
   </h1>
  </div>
  <div class="container" id="xmain">
   ﻿﻿
   <title>
    k最近邻(KNN)分类法介绍，及Java算法实现 | 数盟社区
   </title>
   <!-- All in One SEO Pack 2.2.7.6.2 by Michael Torbert of Semper Fi Web Design[32,71] -->
   <!-- /all in one seo pack -->
   <!--
<div align="center">
<a href="http://strata.oreilly.com.cn/hadoop-big-data-cn?cmp=mp-data-confreg-home-stcn16_dataunion_pc" target="_blank"><img src="http://dataunion.org/wp-content/uploads/2016/05/stratabj.jpg"/ ></a>
</div>
-->
   <header id="header-web">
    <div class="header-main">
     <hgroup class="logo">
      <h1>
       <a href="http://dataunion.org/" rel="home" title="数盟社区">
        <img src="http://dataunion.org/wp-content/themes/yzipi/images/logo.png"/>
       </a>
      </h1>
     </hgroup>
     <!--logo-->
     <nav class="header-nav">
      <ul class="menu" id="menu-%e4%b8%bb%e8%8f%9c%e5%8d%95">
       <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-has-children menu-item-71" id="menu-item-71">
        <a href="http://dataunion.org/category/events" title="events">
         活动
        </a>
        <ul class="sub-menu">
         <li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-22457" id="menu-item-22457">
          <a href="http://dataunion.org/2016timeline">
           2016档期
          </a>
         </li>
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-22459" id="menu-item-22459">
          <a href="http://dataunion.org/category/parterc">
           合作会议
          </a>
         </li>
        </ul>
       </li>
       <li class="menu-item menu-item-type-taxonomy menu-item-object-category current-post-ancestor current-menu-parent current-post-parent menu-item-has-children menu-item-20869" id="menu-item-20869">
        <a href="http://dataunion.org/category/tech" title="articles">
         文章
        </a>
        <ul class="sub-menu">
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-20867" id="menu-item-20867">
          <a href="http://dataunion.org/category/tech/base" title="base">
           基础架构
          </a>
         </li>
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-3302" id="menu-item-3302">
          <a href="http://dataunion.org/category/tech/ai" title="ai">
           人工智能
          </a>
         </li>
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-3303" id="menu-item-3303">
          <a href="http://dataunion.org/category/tech/analysis" title="analysis">
           数据分析
          </a>
         </li>
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-21920" id="menu-item-21920">
          <a href="http://dataunion.org/category/tech/dm">
           数据挖掘
          </a>
         </li>
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-3314" id="menu-item-3314">
          <a href="http://dataunion.org/category/tech/viz" title="viz">
           可视化
          </a>
         </li>
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-3305" id="menu-item-3305">
          <a href="http://dataunion.org/category/tech/devl" title="devl">
           编程语言
          </a>
         </li>
        </ul>
       </li>
       <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-has-children menu-item-20876" id="menu-item-20876">
        <a href="http://dataunion.org/category/industry">
         行业
        </a>
        <ul class="sub-menu">
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-16328" id="menu-item-16328">
          <a href="http://dataunion.org/category/industry/case" title="case">
           行业应用
          </a>
         </li>
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-2112" id="menu-item-2112">
          <a href="http://dataunion.org/category/industry/demo" title="demo">
           Demo展示
          </a>
         </li>
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-21562" id="menu-item-21562">
          <a href="http://dataunion.org/category/industry/news">
           行业资讯
          </a>
         </li>
        </ul>
       </li>
       <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-311" id="menu-item-311">
        <a href="http://dataunion.org/category/sources" title="sources">
         资源
        </a>
       </li>
       <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-20870" id="menu-item-20870">
        <a href="http://dataunion.org/category/books" title="book">
         图书
        </a>
       </li>
       <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-21363" id="menu-item-21363">
        <a href="http://dataunion.org/category/training">
         课程
        </a>
       </li>
       <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-has-children menu-item-21853" id="menu-item-21853">
        <a href="http://dataunion.org/category/jobs">
         职位
        </a>
        <ul class="sub-menu">
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-22050" id="menu-item-22050">
          <a href="http://dataunion.org/category/career">
           职业规划
          </a>
         </li>
        </ul>
       </li>
      </ul>
     </nav>
     <!--header-nav-->
    </div>
   </header>
   <!--header-web-->
   <div id="main">
    <div id="soutab">
     <form action="http://dataunion.org/" class="search" method="get">
     </form>
    </div>
    <div id="container">
     <nav id="mbx">
      当前位置：
      <a href="http://dataunion.org">
       首页
      </a>
      &gt;
      <a href="http://dataunion.org/category/tech">
       文章
      </a>
      &gt;  正文
     </nav>
     <!--mbx-->
     <article class="content">
      <header align="centre" class="contenttitle">
       <div class="mscc">
        <h1 class="mscctitle">
         <a href="http://dataunion.org/16445.html">
          k最近邻(KNN)分类法介绍，及Java算法实现
         </a>
        </h1>
        <address class="msccaddress ">
         <em>
          1,865 次阅读 -
         </em>
         <a href="http://dataunion.org/category/tech" rel="category tag">
          文章
         </a>
        </address>
       </div>
      </header>
      <div class="content-text">
       <p>
        1.
        <strong>
         急切学习与懒惰学习
        </strong>
       </p>
       <p>
        急切学习：在给定训练元组之后、接收到测试元组之前就构造好泛化（即分类）模型。
       </p>
       <p>
        属于急切学习的算法有：决策树、贝叶斯、基于规则的分类、后向传播分类、SVM和基于关联规则挖掘的分类等等。
       </p>
       <p>
        懒惰学习：直至给定一个测试元组才开始构造泛化模型，也称为基于实例的学习法。
       </p>
       <p>
        属于急切学习的算法有：KNN分类、基于案例的推理分类。
       </p>
       <p>
        2.
        <strong>
         KNN的优缺点
        </strong>
       </p>
       <p>
        优点：原理简单，实现起来比较方便。支持增量学习。能对超多边形的复杂决策空间建模。
       </p>
       <p>
        缺点：计算开销大，需要有效的存储技术和并行硬件的支撑。
       </p>
       <p>
        3.
        <strong>
         KNN算法原理
        </strong>
       </p>
       <p>
        基于类比学习，通过比较训练元组和测试元组的相似度来学习。
       </p>
       <p>
        将训练元组和测试元组看作是n维（若元组有n的属性）空间内的点，给定一条测试元组，搜索n维空间，找出与测试
       </p>
       <p>
        元组最相近的k个点（即训练元组），最后取这k个点中的多数类作为测试元组的类别。
       </p>
       <p>
        相近的度量方法：用空间内两个点的距离来度量。距离越大，表示两个点越不相似。
       </p>
       <p>
        距离的选择：可采用欧几里得距离、曼哈顿距离或其它距离度量。多采用欧几里得距离，简单！
       </p>
       <p>
        4.
        <strong>
         KNN算法中的细节处理
        </strong>
       </p>
       <ul>
        <li>
         数值属性规范化：将数值属性规范到0-1区间以便于计算，也可防止大数值型属性对分类的主导作用。
        </li>
       </ul>
       <p>
        可选的方法有：v’ = （v – v
        <sub>
         min
        </sub>
        ）/ (v
        <sub>
         max
        </sub>
        – v
        <sub>
         min
        </sub>
        )，当然也可以采用其它的规范化方法
       </p>
       <ul>
        <li>
         比较的属性是分类类型而不是数值类型的：同则差为0，异则差为1.
        </li>
       </ul>
       <p>
        有时候可以作更为精确的处理，比如黑色与白色的差肯定要大于灰色与白色的差。
       </p>
       <ul>
        <li>
         缺失值的处理：取最大的可能差，对于分类属性，如果属性A的一个或两个对应值丢失，则取差值为1；
        </li>
       </ul>
       <p>
        如果A是数值属性，若两个比较的元组A属性值均缺失，则取差值为1，若只有一个缺失，另一个值为v，
       </p>
       <p>
        则取差值为｜1-v｜和｜0-v｜中的最大值
       </p>
       <ul>
        <li>
         确定K的值：通过实验确定。进行若干次实验，取分类误差率最小的k值。
        </li>
       </ul>
       <ul>
        <li>
         对噪声数据或不相关属性的处理：对属性赋予相关性权重w，w越大说明属性对分类的影响越相关。对噪声数据可以将所在
        </li>
       </ul>
       <p>
        的元组直接cut掉。
       </p>
       <p>
        5.
        <strong>
         KNN算法流程
        </strong>
       </p>
       <ul>
        <li>
         准备数据，对数据进行预处理
        </li>
        <li>
         选用合适的数据结构存储训练数据和测试元组
        </li>
        <li>
         设定参数，如k
        </li>
        <li>
         维护一个大小为k的的按距离由大到小的优先级队列，用于存储最近邻训练元组
        </li>
        <li>
         随机从训练元组中选取k个元组作为初始的最近邻元组，分别计算测试元组到这k个元组的距离，将训练元组标号和距离存入优先级队列
        </li>
        <li>
         遍历训练元组集，计算当前训练元组与测试元组的距离，将所得距离L与优先级队列中的最大距离L
         <sub>
          max
         </sub>
         进行比较。若L&gt;=L
         <sub>
          max，则舍弃该元组，遍历下一个元组。若L &lt;
         </sub>
         L
         <sub>
          max，删除优先级队列中最大距离的元组，将当前训练元组存入优先级队列。
         </sub>
        </li>
        <li>
         <sub>
          遍历完毕，计算优先级队列中k个元组的多数类，并将其作为测试元组的类别。
         </sub>
        </li>
        <li>
         <sub>
          测试元组集测试完毕后计算误差率，继续设定不同的k值重新进行训练，最后取误差率最小的k值。
         </sub>
        </li>
       </ul>
       <p>
        6.
        <strong>
         KNN算法的改进策略
        </strong>
       </p>
       <ul>
        <li>
         将存储的训练元组预先排序并安排在搜索树中（如何排序有待研究）
        </li>
        <li>
         并行实现
        </li>
        <li>
         部分距离计算，取n个属性的“子集”计算出部分距离，若超过设定的阈值则停止对当前元组作进一步计算。转向下一个元组。
        </li>
        <li>
         剪枝或精简：删除证明是“无用的”元组。
        </li>
       </ul>
       <p>
        7.
        <strong>
         KNN算法java实现
        </strong>
       </p>
       <p>
        本算法只适合学习使用，可以大致了解一下KNN算法的原理。
       </p>
       <p>
        算法作了如下的假定与简化处理：
       </p>
       <p>
        1.小规模数据集
       </p>
       <p>
        2.假设所有数据及类别都是数值类型的
       </p>
       <p>
        3.直接根据数据规模设定了k值
       </p>
       <p>
        4.对原训练集进行测试
       </p>
       <p>
       </p>
       <p>
        KNN实现代码如下：
       </p>
       <div class="dp-highlighter bg_java">
        <div class="bar">
         <div class="tools">
          <b>
           [java]
          </b>
         </div>
        </div>
        <ol class="dp-j" start="1">
         <li class="alt">
          <span class="keyword">
           package
          </span>
          KNN;
         </li>
         <li class="">
          <span class="comment">
           /**
          </span>
         </li>
         <li class="alt">
          <span class="comment">
           * KNN结点类，用来存储最近邻的k个元组相关的信息
          </span>
         </li>
         <li class="">
          <span class="comment">
           * @author Rowen
          </span>
         </li>
         <li class="alt">
          <span class="comment">
           * @qq 443773264
          </span>
         </li>
         <li class="">
          <span class="comment">
           * @mail luowen3405@163.com
          </span>
         </li>
         <li class="alt">
          <span class="comment">
           * @blog blog.csdn.net/luowen3405
          </span>
         </li>
         <li class="">
          <span class="comment">
           * @data 2011.03.25
          </span>
         </li>
         <li class="alt">
          <span class="comment">
           */
          </span>
         </li>
         <li class="">
          <span class="keyword">
           public
          </span>
          <span class="keyword">
           class
          </span>
          KNNNode {
         </li>
         <li class="alt">
          <span class="keyword">
           private
          </span>
          <span class="keyword">
           int
          </span>
          index;
          <span class="comment">
           // 元组标号
          </span>
         </li>
         <li class="">
          <span class="keyword">
           private
          </span>
          <span class="keyword">
           double
          </span>
          distance;
          <span class="comment">
           // 与测试元组的距离
          </span>
         </li>
         <li class="alt">
          <span class="keyword">
           private
          </span>
          String c;
          <span class="comment">
           // 所属类别
          </span>
         </li>
         <li class="">
          <span class="keyword">
           public
          </span>
          KNNNode(
          <span class="keyword">
           int
          </span>
          index,
          <span class="keyword">
           double
          </span>
          distance, String c) {
         </li>
         <li class="alt">
          <span class="keyword">
           super
          </span>
          ();
         </li>
         <li class="">
          <span class="keyword">
           this
          </span>
          .index = index;
         </li>
         <li class="alt">
          <span class="keyword">
           this
          </span>
          .distance = distance;
         </li>
         <li class="">
          <span class="keyword">
           this
          </span>
          .c = c;
         </li>
         <li class="alt">
          }
         </li>
         <li class="">
         </li>
         <li class="alt">
         </li>
         <li class="">
          <span class="keyword">
           public
          </span>
          <span class="keyword">
           int
          </span>
          getIndex() {
         </li>
         <li class="alt">
          <span class="keyword">
           return
          </span>
          index;
         </li>
         <li class="">
          }
         </li>
         <li class="alt">
          <span class="keyword">
           public
          </span>
          <span class="keyword">
           void
          </span>
          setIndex(
          <span class="keyword">
           int
          </span>
          index) {
         </li>
         <li class="">
          <span class="keyword">
           this
          </span>
          .index = index;
         </li>
         <li class="alt">
          }
         </li>
         <li class="">
          <span class="keyword">
           public
          </span>
          <span class="keyword">
           double
          </span>
          getDistance() {
         </li>
         <li class="alt">
          <span class="keyword">
           return
          </span>
          distance;
         </li>
         <li class="">
          }
         </li>
         <li class="alt">
          <span class="keyword">
           public
          </span>
          <span class="keyword">
           void
          </span>
          setDistance(
          <span class="keyword">
           double
          </span>
          distance) {
         </li>
         <li class="">
          <span class="keyword">
           this
          </span>
          .distance = distance;
         </li>
         <li class="alt">
          }
         </li>
         <li class="">
          <span class="keyword">
           public
          </span>
          String getC() {
         </li>
         <li class="alt">
          <span class="keyword">
           return
          </span>
          c;
         </li>
         <li class="">
          }
         </li>
         <li class="alt">
          <span class="keyword">
           public
          </span>
          <span class="keyword">
           void
          </span>
          setC(String c) {
         </li>
         <li class="">
          <span class="keyword">
           this
          </span>
          .c = c;
         </li>
         <li class="alt">
          }
         </li>
         <li class="">
          }
         </li>
        </ol>
       </div>
       <p>
       </p>
       <div class="dp-highlighter bg_java">
        <div class="bar">
         <div class="tools">
          <b>
           [java]
          </b>
         </div>
        </div>
        <ol class="dp-j" start="1">
         <li class="alt">
          <span class="keyword">
           package
          </span>
          KNN;
         </li>
         <li class="">
          <span class="keyword">
           import
          </span>
          java.util.ArrayList;
         </li>
         <li class="alt">
          <span class="keyword">
           import
          </span>
          java.util.Comparator;
         </li>
         <li class="">
          <span class="keyword">
           import
          </span>
          java.util.HashMap;
         </li>
         <li class="alt">
          <span class="keyword">
           import
          </span>
          java.util.List;
         </li>
         <li class="">
          <span class="keyword">
           import
          </span>
          java.util.Map;
         </li>
         <li class="alt">
          <span class="keyword">
           import
          </span>
          java.util.PriorityQueue;
         </li>
         <li class="">
         </li>
         <li class="alt">
          <span class="comment">
           /**
          </span>
         </li>
         <li class="">
          <span class="comment">
           * KNN算法主体类
          </span>
         </li>
         <li class="alt">
          <span class="comment">
           * @author Rowen
          </span>
         </li>
         <li class="">
          <span class="comment">
           * @qq 443773264
          </span>
         </li>
         <li class="alt">
          <span class="comment">
           * @mail luowen3405@163.com
          </span>
         </li>
         <li class="">
          <span class="comment">
           * @blog blog.csdn.net/luowen3405
          </span>
         </li>
         <li class="alt">
          <span class="comment">
           * @data 2011.03.25
          </span>
         </li>
         <li class="">
          <span class="comment">
           */
          </span>
         </li>
         <li class="alt">
          <span class="keyword">
           public
          </span>
          <span class="keyword">
           class
          </span>
          KNN {
         </li>
         <li class="">
          <span class="comment">
           /**
          </span>
         </li>
         <li class="alt">
          <span class="comment">
           * 设置优先级队列的比较函数，距离越大，优先级越高
          </span>
         </li>
         <li class="">
          <span class="comment">
           */
          </span>
         </li>
         <li class="alt">
          <span class="keyword">
           private
          </span>
          Comparator&lt;KNNNode&gt; comparator =
          <span class="keyword">
           new
          </span>
          Comparator&lt;KNNNode&gt;() {
         </li>
         <li class="">
          <span class="keyword">
           public
          </span>
          <span class="keyword">
           int
          </span>
          compare(KNNNode o1, KNNNode o2) {
         </li>
         <li class="alt">
          <span class="keyword">
           if
          </span>
          (o1.getDistance() &gt;= o2.getDistance()) {
         </li>
         <li class="">
          <span class="keyword">
           return
          </span>
          <span class="number">
           1
          </span>
          ;
         </li>
         <li class="alt">
          }
          <span class="keyword">
           else
          </span>
          {
         </li>
         <li class="">
          <span class="keyword">
           return
          </span>
          <span class="number">
           0
          </span>
          ;
         </li>
         <li class="alt">
          }
         </li>
         <li class="">
          }
         </li>
         <li class="alt">
          };
         </li>
         <li class="">
          <span class="comment">
           /**
          </span>
         </li>
         <li class="alt">
          <span class="comment">
           * 获取K个不同的随机数
          </span>
         </li>
         <li class="">
          <span class="comment">
           * @param k 随机数的个数
          </span>
         </li>
         <li class="alt">
          <span class="comment">
           * @param max 随机数最大的范围
          </span>
         </li>
         <li class="">
          <span class="comment">
           * @return 生成的随机数数组
          </span>
         </li>
         <li class="alt">
          <span class="comment">
           */
          </span>
         </li>
         <li class="">
          <span class="keyword">
           public
          </span>
          List&lt;Integer&gt; getRandKNum(
          <span class="keyword">
           int
          </span>
          k,
          <span class="keyword">
           int
          </span>
          max) {
         </li>
         <li class="alt">
          List&lt;Integer&gt; rand =
          <span class="keyword">
           new
          </span>
          ArrayList&lt;Integer&gt;(k);
         </li>
         <li class="">
          <span class="keyword">
           for
          </span>
          (
          <span class="keyword">
           int
          </span>
          i =
          <span class="number">
           0
          </span>
          ; i &lt; k; i++) {
         </li>
         <li class="alt">
          <span class="keyword">
           int
          </span>
          temp = (
          <span class="keyword">
           int
          </span>
          ) (Math.random() * max);
         </li>
         <li class="">
          <span class="keyword">
           if
          </span>
          (!rand.contains(temp)) {
         </li>
         <li class="alt">
          rand.add(temp);
         </li>
         <li class="">
          }
          <span class="keyword">
           else
          </span>
          {
         </li>
         <li class="alt">
          i–;
         </li>
         <li class="">
          }
         </li>
         <li class="alt">
          }
         </li>
         <li class="">
          <span class="keyword">
           return
          </span>
          rand;
         </li>
         <li class="alt">
          }
         </li>
         <li class="">
          <span class="comment">
           /**
          </span>
         </li>
         <li class="alt">
          <span class="comment">
           * 计算测试元组与训练元组之前的距离
          </span>
         </li>
         <li class="">
          <span class="comment">
           * @param d1 测试元组
          </span>
         </li>
         <li class="alt">
          <span class="comment">
           * @param d2 训练元组
          </span>
         </li>
         <li class="">
          <span class="comment">
           * @return 距离值
          </span>
         </li>
         <li class="alt">
          <span class="comment">
           */
          </span>
         </li>
         <li class="">
          <span class="keyword">
           public
          </span>
          <span class="keyword">
           double
          </span>
          calDistance(List&lt;Double&gt; d1, List&lt;Double&gt; d2) {
         </li>
         <li class="alt">
          <span class="keyword">
           double
          </span>
          distance =
          <span class="number">
           0.00
          </span>
          ;
         </li>
         <li class="">
          <span class="keyword">
           for
          </span>
          (
          <span class="keyword">
           int
          </span>
          i =
          <span class="number">
           0
          </span>
          ; i &lt; d1.size(); i++) {
         </li>
         <li class="alt">
          distance += (d1.get(i) – d2.get(i)) * (d1.get(i) – d2.get(i));
         </li>
         <li class="">
          }
         </li>
         <li class="alt">
          <span class="keyword">
           return
          </span>
          distance;
         </li>
         <li class="">
          }
         </li>
         <li class="alt">
          <span class="comment">
           /**
          </span>
         </li>
         <li class="">
          <span class="comment">
           * 执行KNN算法，获取测试元组的类别
          </span>
         </li>
         <li class="alt">
          <span class="comment">
           * @param datas 训练数据集
          </span>
         </li>
         <li class="">
          <span class="comment">
           * @param testData 测试元组
          </span>
         </li>
         <li class="alt">
          <span class="comment">
           * @param k 设定的K值
          </span>
         </li>
         <li class="">
          <span class="comment">
           * @return 测试元组的类别
          </span>
         </li>
         <li class="alt">
          <span class="comment">
           */
          </span>
         </li>
         <li class="">
          <span class="keyword">
           public
          </span>
          String knn(List&lt;List&lt;Double&gt;&gt; datas, List&lt;Double&gt; testData,
          <span class="keyword">
           int
          </span>
          k) {
         </li>
         <li class="alt">
          PriorityQueue&lt;KNNNode&gt; pq =
          <span class="keyword">
           new
          </span>
          PriorityQueue&lt;KNNNode&gt;(k, comparator);
         </li>
         <li class="">
          List&lt;Integer&gt; randNum = getRandKNum(k, datas.size());
         </li>
         <li class="alt">
          <span class="keyword">
           for
          </span>
          (
          <span class="keyword">
           int
          </span>
          i =
          <span class="number">
           0
          </span>
          ; i &lt; k; i++) {
         </li>
         <li class="">
          <span class="keyword">
           int
          </span>
          index = randNum.get(i);
         </li>
         <li class="alt">
          List&lt;Double&gt; currData = datas.get(index);
         </li>
         <li class="">
          String c = currData.get(currData.size() –
          <span class="number">
           1
          </span>
          ).toString();
         </li>
         <li class="alt">
          KNNNode node =
          <span class="keyword">
           new
          </span>
          KNNNode(index, calDistance(testData, currData), c);
         </li>
         <li class="">
          pq.add(node);
         </li>
         <li class="alt">
          }
         </li>
         <li class="">
          <span class="keyword">
           for
          </span>
          (
          <span class="keyword">
           int
          </span>
          i =
          <span class="number">
           0
          </span>
          ; i &lt; datas.size(); i++) {
         </li>
         <li class="alt">
          List&lt;Double&gt; t = datas.get(i);
         </li>
         <li class="">
          <span class="keyword">
           double
          </span>
          distance = calDistance(testData, t);
         </li>
         <li class="alt">
          KNNNode top = pq.peek();
         </li>
         <li class="">
          <span class="keyword">
           if
          </span>
          (top.getDistance() &gt; distance) {
         </li>
         <li class="alt">
          pq.remove();
         </li>
         <li class="">
          pq.add(
          <span class="keyword">
           new
          </span>
          KNNNode(i, distance, t.get(t.size() –
          <span class="number">
           1
          </span>
          ).toString()));
         </li>
         <li class="alt">
          }
         </li>
         <li class="">
          }
         </li>
         <li class="alt">
         </li>
         <li class="">
          <span class="keyword">
           return
          </span>
          getMostClass(pq);
         </li>
         <li class="alt">
          }
         </li>
         <li class="">
          <span class="comment">
           /**
          </span>
         </li>
         <li class="alt">
          <span class="comment">
           * 获取所得到的k个最近邻元组的多数类
          </span>
         </li>
         <li class="">
          <span class="comment">
           * @param pq 存储k个最近近邻元组的优先级队列
          </span>
         </li>
         <li class="alt">
          <span class="comment">
           * @return 多数类的名称
          </span>
         </li>
         <li class="">
          <span class="comment">
           */
          </span>
         </li>
         <li class="alt">
          <span class="keyword">
           private
          </span>
          String getMostClass(PriorityQueue&lt;KNNNode&gt; pq) {
         </li>
         <li class="">
          Map&lt;String, Integer&gt; classCount =
          <span class="keyword">
           new
          </span>
          HashMap&lt;String, Integer&gt;();
         </li>
         <li class="alt">
          <span class="keyword">
           for
          </span>
          (
          <span class="keyword">
           int
          </span>
          i =
          <span class="number">
           0
          </span>
          ; i &lt; pq.size(); i++) {
         </li>
         <li class="">
          KNNNode node = pq.remove();
         </li>
         <li class="alt">
          String c = node.getC();
         </li>
         <li class="">
          <span class="keyword">
           if
          </span>
          (classCount.containsKey(c)) {
         </li>
         <li class="alt">
          classCount.put(c, classCount.get(c) +
          <span class="number">
           1
          </span>
          );
         </li>
         <li class="">
          }
          <span class="keyword">
           else
          </span>
          {
         </li>
         <li class="alt">
          classCount.put(c,
          <span class="number">
           1
          </span>
          );
         </li>
         <li class="">
          }
         </li>
         <li class="alt">
          }
         </li>
         <li class="">
          <span class="keyword">
           int
          </span>
          maxIndex = –
          <span class="number">
           1
          </span>
          ;
         </li>
         <li class="alt">
          <span class="keyword">
           int
          </span>
          maxCount =
          <span class="number">
           0
          </span>
          ;
         </li>
         <li class="">
          Object[] classes = classCount.keySet().toArray();
         </li>
         <li class="alt">
          <span class="keyword">
           for
          </span>
          (
          <span class="keyword">
           int
          </span>
          i =
          <span class="number">
           0
          </span>
          ; i &lt; classes.length; i++) {
         </li>
         <li class="">
          <span class="keyword">
           if
          </span>
          (classCount.get(classes[i]) &gt; maxCount) {
         </li>
         <li class="alt">
          maxIndex = i;
         </li>
         <li class="">
          maxCount = classCount.get(classes[i]);
         </li>
         <li class="alt">
          }
         </li>
         <li class="">
          }
         </li>
         <li class="alt">
          <span class="keyword">
           return
          </span>
          classes[maxIndex].toString();
         </li>
         <li class="">
          }
         </li>
         <li class="alt">
          }
         </li>
        </ol>
       </div>
       <div class="dp-highlighter bg_java">
        <div class="bar">
         <div class="tools">
          <b>
           [java]
          </b>
         </div>
        </div>
        <ol class="dp-j" start="1">
         <li class="alt">
          <span class="keyword">
           package
          </span>
          KNN;
         </li>
         <li class="">
          <span class="keyword">
           import
          </span>
          java.io.BufferedReader;
         </li>
         <li class="alt">
          <span class="keyword">
           import
          </span>
          java.io.File;
         </li>
         <li class="">
          <span class="keyword">
           import
          </span>
          java.io.FileReader;
         </li>
         <li class="alt">
          <span class="keyword">
           import
          </span>
          java.util.ArrayList;
         </li>
         <li class="">
          <span class="keyword">
           import
          </span>
          java.util.List;
         </li>
         <li class="alt">
          <span class="comment">
           /**
          </span>
         </li>
         <li class="">
          <span class="comment">
           * KNN算法测试类
          </span>
         </li>
         <li class="alt">
          <span class="comment">
           * @author Rowen
          </span>
         </li>
         <li class="">
          <span class="comment">
           * @qq 443773264
          </span>
         </li>
         <li class="alt">
          <span class="comment">
           * @mail luowen3405@163.com
          </span>
         </li>
         <li class="">
          <span class="comment">
           * @blog blog.csdn.net/luowen3405
          </span>
         </li>
         <li class="alt">
          <span class="comment">
           * @data 2011.03.25
          </span>
         </li>
         <li class="">
          <span class="comment">
           */
          </span>
         </li>
         <li class="alt">
          <span class="keyword">
           public
          </span>
          <span class="keyword">
           class
          </span>
          TestKNN {
         </li>
         <li class="">
         </li>
         <li class="alt">
          <span class="comment">
           /**
          </span>
         </li>
         <li class="">
          <span class="comment">
           * 从数据文件中读取数据
          </span>
         </li>
         <li class="alt">
          <span class="comment">
           * @param datas 存储数据的集合对象
          </span>
         </li>
         <li class="">
          <span class="comment">
           * @param path 数据文件的路径
          </span>
         </li>
         <li class="alt">
          <span class="comment">
           */
          </span>
         </li>
         <li class="">
          <span class="keyword">
           public
          </span>
          <span class="keyword">
           void
          </span>
          read(List&lt;List&lt;Double&gt;&gt; datas, String path){
         </li>
         <li class="alt">
          <span class="keyword">
           try
          </span>
          {
         </li>
         <li class="">
          BufferedReader br =
          <span class="keyword">
           new
          </span>
          BufferedReader(
          <span class="keyword">
           new
          </span>
          FileReader(
          <span class="keyword">
           new
          </span>
          File(path)));
         </li>
         <li class="alt">
          String data = br.readLine();
         </li>
         <li class="">
          List&lt;Double&gt; l =
          <span class="keyword">
           null
          </span>
          ;
         </li>
         <li class="alt">
          <span class="keyword">
           while
          </span>
          (data !=
          <span class="keyword">
           null
          </span>
          ) {
         </li>
         <li class="">
          String t[] = data.split(
          <span class="string">
           ” “
          </span>
          );
         </li>
         <li class="alt">
          l =
          <span class="keyword">
           new
          </span>
          ArrayList&lt;Double&gt;();
         </li>
         <li class="">
          <span class="keyword">
           for
          </span>
          (
          <span class="keyword">
           int
          </span>
          i =
          <span class="number">
           0
          </span>
          ; i &lt; t.length; i++) {
         </li>
         <li class="alt">
          l.add(Double.parseDouble(t[i]));
         </li>
         <li class="">
          }
         </li>
         <li class="alt">
          datas.add(l);
         </li>
         <li class="">
          data = br.readLine();
         </li>
         <li class="alt">
          }
         </li>
         <li class="">
          }
          <span class="keyword">
           catch
          </span>
          (Exception e) {
         </li>
         <li class="alt">
          e.printStackTrace();
         </li>
         <li class="">
          }
         </li>
         <li class="alt">
          }
         </li>
         <li class="">
         </li>
         <li class="alt">
          <span class="comment">
           /**
          </span>
         </li>
         <li class="">
          <span class="comment">
           * 程序执行入口
          </span>
         </li>
         <li class="alt">
          <span class="comment">
           * @param args
          </span>
         </li>
         <li class="">
          <span class="comment">
           */
          </span>
         </li>
         <li class="alt">
          <span class="keyword">
           public
          </span>
          <span class="keyword">
           static
          </span>
          <span class="keyword">
           void
          </span>
          main(String[] args) {
         </li>
         <li class="">
          TestKNN t =
          <span class="keyword">
           new
          </span>
          TestKNN();
         </li>
         <li class="alt">
          String datafile =
          <span class="keyword">
           new
          </span>
          File(
          <span class="string">
           “”
          </span>
          ).getAbsolutePath() + File.separator +
          <span class="string">
           “datafile”
          </span>
          ;
         </li>
         <li class="">
          String testfile =
          <span class="keyword">
           new
          </span>
          File(
          <span class="string">
           “”
          </span>
          ).getAbsolutePath() + File.separator +
          <span class="string">
           “testfile”
          </span>
          ;
         </li>
         <li class="alt">
          <span class="keyword">
           try
          </span>
          {
         </li>
         <li class="">
          List&lt;List&lt;Double&gt;&gt; datas =
          <span class="keyword">
           new
          </span>
          ArrayList&lt;List&lt;Double&gt;&gt;();
         </li>
         <li class="alt">
          List&lt;List&lt;Double&gt;&gt; testDatas =
          <span class="keyword">
           new
          </span>
          ArrayList&lt;List&lt;Double&gt;&gt;();
         </li>
         <li class="">
          t.read(datas, datafile);
         </li>
         <li class="alt">
          t.read(testDatas, testfile);
         </li>
         <li class="">
          KNN knn =
          <span class="keyword">
           new
          </span>
          KNN();
         </li>
         <li class="alt">
          <span class="keyword">
           for
          </span>
          (
          <span class="keyword">
           int
          </span>
          i =
          <span class="number">
           0
          </span>
          ; i &lt; testDatas.size(); i++) {
         </li>
         <li class="">
          List&lt;Double&gt; test = testDatas.get(i);
         </li>
         <li class="alt">
          System.out.print(
          <span class="string">
           “测试元组: “
          </span>
          );
         </li>
         <li class="">
          <span class="keyword">
           for
          </span>
          (
          <span class="keyword">
           int
          </span>
          j =
          <span class="number">
           0
          </span>
          ; j &lt; test.size(); j++) {
         </li>
         <li class="alt">
          System.out.print(test.get(j) +
          <span class="string">
           ” “
          </span>
          );
         </li>
         <li class="">
          }
         </li>
         <li class="alt">
          System.out.print(
          <span class="string">
           “类别为: “
          </span>
          );
         </li>
         <li class="">
          System.out.println(Math.round(Float.parseFloat((knn.knn(datas, test,
          <span class="number">
           3
          </span>
          )))));
         </li>
         <li class="alt">
          }
         </li>
         <li class="">
          }
          <span class="keyword">
           catch
          </span>
          (Exception e) {
         </li>
         <li class="alt">
          e.printStackTrace();
         </li>
         <li class="">
          }
         </li>
         <li class="alt">
          }
         </li>
         <li class="">
          }
         </li>
        </ol>
       </div>
       <p>
       </p>
       <p>
       </p>
       <p>
        训练数据文件：
       </p>
       <div class="dp-highlighter bg_java">
        <div class="bar">
         <div class="tools">
          <b>
           [java]
          </b>
         </div>
        </div>
        <ol class="dp-j" start="1">
         <li class="alt">
          <span class="number">
           1.0
          </span>
          <span class="number">
           1.1
          </span>
          <span class="number">
           1.2
          </span>
          <span class="number">
           2.1
          </span>
          <span class="number">
           0.3
          </span>
          <span class="number">
           2.3
          </span>
          <span class="number">
           1.4
          </span>
          <span class="number">
           0.5
          </span>
          <span class="number">
           1
          </span>
         </li>
         <li class="">
          <span class="number">
           1.7
          </span>
          <span class="number">
           1.2
          </span>
          <span class="number">
           1.4
          </span>
          <span class="number">
           2.0
          </span>
          <span class="number">
           0.2
          </span>
          <span class="number">
           2.5
          </span>
          <span class="number">
           1.2
          </span>
          <span class="number">
           0.8
          </span>
          <span class="number">
           1
          </span>
         </li>
         <li class="alt">
          <span class="number">
           1.2
          </span>
          <span class="number">
           1.8
          </span>
          <span class="number">
           1.6
          </span>
          <span class="number">
           2.5
          </span>
          <span class="number">
           0.1
          </span>
          <span class="number">
           2.2
          </span>
          <span class="number">
           1.8
          </span>
          <span class="number">
           0.2
          </span>
          <span class="number">
           1
          </span>
         </li>
         <li class="">
          <span class="number">
           1.9
          </span>
          <span class="number">
           2.1
          </span>
          <span class="number">
           6.2
          </span>
          <span class="number">
           1.1
          </span>
          <span class="number">
           0.9
          </span>
          <span class="number">
           3.3
          </span>
          <span class="number">
           2.4
          </span>
          <span class="number">
           5.5
          </span>
          <span class="number">
           0
          </span>
         </li>
         <li class="alt">
          <span class="number">
           1.0
          </span>
          <span class="number">
           0.8
          </span>
          <span class="number">
           1.6
          </span>
          <span class="number">
           2.1
          </span>
          <span class="number">
           0.2
          </span>
          <span class="number">
           2.3
          </span>
          <span class="number">
           1.6
          </span>
          <span class="number">
           0.5
          </span>
          <span class="number">
           1
          </span>
         </li>
         <li class="">
          <span class="number">
           1.6
          </span>
          <span class="number">
           2.1
          </span>
          <span class="number">
           5.2
          </span>
          <span class="number">
           1.1
          </span>
          <span class="number">
           0.8
          </span>
          <span class="number">
           3.6
          </span>
          <span class="number">
           2.4
          </span>
          <span class="number">
           4.5
          </span>
          <span class="number">
           0
          </span>
         </li>
        </ol>
       </div>
       <p>
       </p>
       <p>
       </p>
       <div class="dp-highlighter bg_java">
        <div class="bar">
         <div class="tools">
          <b>
           [java]
          </b>
         </div>
        </div>
        <ol class="dp-j" start="1">
         <li class="alt">
          <span class="number">
           1.0
          </span>
          <span class="number">
           1.1
          </span>
          <span class="number">
           1.2
          </span>
          <span class="number">
           2.1
          </span>
          <span class="number">
           0.3
          </span>
          <span class="number">
           2.3
          </span>
          <span class="number">
           1.4
          </span>
          <span class="number">
           0.5
          </span>
         </li>
         <li class="">
          <span class="number">
           1.7
          </span>
          <span class="number">
           1.2
          </span>
          <span class="number">
           1.4
          </span>
          <span class="number">
           2.0
          </span>
          <span class="number">
           0.2
          </span>
          <span class="number">
           2.5
          </span>
          <span class="number">
           1.2
          </span>
          <span class="number">
           0.8
          </span>
         </li>
         <li class="alt">
          <span class="number">
           1.2
          </span>
          <span class="number">
           1.8
          </span>
          <span class="number">
           1.6
          </span>
          <span class="number">
           2.5
          </span>
          <span class="number">
           0.1
          </span>
          <span class="number">
           2.2
          </span>
          <span class="number">
           1.8
          </span>
          <span class="number">
           0.2
          </span>
         </li>
         <li class="">
          <span class="number">
           1.9
          </span>
          <span class="number">
           2.1
          </span>
          <span class="number">
           6.2
          </span>
          <span class="number">
           1.1
          </span>
          <span class="number">
           0.9
          </span>
          <span class="number">
           3.3
          </span>
          <span class="number">
           2.4
          </span>
          <span class="number">
           5.5
          </span>
         </li>
         <li class="alt">
          <span class="number">
           1.0
          </span>
          <span class="number">
           0.8
          </span>
          <span class="number">
           1.6
          </span>
          <span class="number">
           2.1
          </span>
          <span class="number">
           0.2
          </span>
          <span class="number">
           2.3
          </span>
          <span class="number">
           1.6
          </span>
          <span class="number">
           0.5
          </span>
         </li>
         <li class="">
          <span class="number">
           1.6
          </span>
          <span class="number">
           2.1
          </span>
          <span class="number">
           5.2
          </span>
          <span class="number">
           1.1
          </span>
          <span class="number">
           0.8
          </span>
          <span class="number">
           3.6
          </span>
          <span class="number">
           2.4
          </span>
          <span class="number">
           4.5
          </span>
         </li>
        </ol>
       </div>
       <p>
       </p>
       <p>
       </p>
       <p>
        程序运行结果：
       </p>
       <div class="dp-highlighter bg_java">
        <div class="bar">
         <div class="tools">
          <b>
           [java]
          </b>
          <p>
          </p>
          <div>
          </div>
         </div>
        </div>
        <ol class="dp-j" start="1">
         <li class="alt">
          测试元组:
          <span class="number">
           1.0
          </span>
          <span class="number">
           1.1
          </span>
          <span class="number">
           1.2
          </span>
          <span class="number">
           2.1
          </span>
          <span class="number">
           0.3
          </span>
          <span class="number">
           2.3
          </span>
          <span class="number">
           1.4
          </span>
          <span class="number">
           0.5
          </span>
          类别为:
          <span class="number">
           1
          </span>
         </li>
         <li class="">
          测试元组:
          <span class="number">
           1.7
          </span>
          <span class="number">
           1.2
          </span>
          <span class="number">
           1.4
          </span>
          <span class="number">
           2.0
          </span>
          <span class="number">
           0.2
          </span>
          <span class="number">
           2.5
          </span>
          <span class="number">
           1.2
          </span>
          <span class="number">
           0.8
          </span>
          类别为:
          <span class="number">
           1
          </span>
         </li>
         <li class="alt">
          测试元组:
          <span class="number">
           1.2
          </span>
          <span class="number">
           1.8
          </span>
          <span class="number">
           1.6
          </span>
          <span class="number">
           2.5
          </span>
          <span class="number">
           0.1
          </span>
          <span class="number">
           2.2
          </span>
          <span class="number">
           1.8
          </span>
          <span class="number">
           0.2
          </span>
          类别为:
          <span class="number">
           1
          </span>
         </li>
         <li class="">
          测试元组:
          <span class="number">
           1.9
          </span>
          <span class="number">
           2.1
          </span>
          <span class="number">
           6.2
          </span>
          <span class="number">
           1.1
          </span>
          <span class="number">
           0.9
          </span>
          <span class="number">
           3.3
          </span>
          <span class="number">
           2.4
          </span>
          <span class="number">
           5.5
          </span>
          类别为:
          <span class="number">
           0
          </span>
         </li>
         <li class="alt">
          测试元组:
          <span class="number">
           1.0
          </span>
          <span class="number">
           0.8
          </span>
          <span class="number">
           1.6
          </span>
          <span class="number">
           2.1
          </span>
          <span class="number">
           0.2
          </span>
          <span class="number">
           2.3
          </span>
          <span class="number">
           1.6
          </span>
          <span class="number">
           0.5
          </span>
          类别为:
          <span class="number">
           1
          </span>
         </li>
         <li class="">
          测试元组:
          <span class="number">
           1.6
          </span>
          <span class="number">
           2.1
          </span>
          <span class="number">
           5.2
          </span>
          <span class="number">
           1.1
          </span>
          <span class="number">
           0.8
          </span>
          <span class="number">
           3.6
          </span>
          <span class="number">
           2.4
          </span>
          <span class="number">
           4.5
          </span>
          类别为:
          <span class="number">
           0
          </span>
         </li>
        </ol>
       </div>
       <p>
       </p>
       <p>
        作者：
        <a class="user_name" href="http://my.csdn.net/luowen3405" target="_blank">
         luowen3405
        </a>
       </p>
       <p>
        文章出处：
        <a href="http://blog.csdn.net/luowen3405/article/details/6275254">
         http://blog.csdn.net/luowen3405/article/details/6275254
        </a>
       </p>
      </div>
      <div>
       <strong>
        注：转载文章均来自于公开网络，仅供学习使用，不会用于任何商业用途，如果侵犯到原作者的权益，请您与我们联系删除或者授权事宜，联系邮箱：contact@dataunion.org。转载数盟网站文章请注明原文章作者，否则产生的任何版权纠纷与数盟无关。
       </strong>
      </div>
      <!--content_text-->
      <div class="fenxian">
       <!-- JiaThis Button BEGIN -->
       <div class="jiathis_style_32x32">
        <p class="jiathis_button_weixin">
        </p>
        <p class="jiathis_button_tsina">
        </p>
        <p class="jiathis_button_qzone">
        </p>
        <p class="jiathis_button_cqq">
        </p>
        <p class="jiathis_button_tumblr">
        </p>
        <a class="jiathis jiathis_txt jtico jtico_jiathis" href="http://www.jiathis.com/share" target="_blank">
        </a>
        <p class="jiathis_counter_style">
        </p>
       </div>
       <!-- JiaThis Button END -->
      </div>
     </article>
     <!--content-->
     <!--相关文章-->
     <div class="xianguan">
      <div class="xianguantitle">
       相关文章！
      </div>
      <ul class="pic">
       <li>
        <a href="http://dataunion.org/5911.html">
         <img src="http://dataunion.org/wp-content/uploads/2015/01/EvYJNr-300x139.png"/>
        </a>
        <a class="link" href="http://dataunion.org/5911.html" rel="bookmark" title="基于稀疏矩阵的k近邻（KNN）实现">
         基于稀疏矩阵的k近邻（KNN）实现
        </a>
       </li>
       <li>
        <a href="http://dataunion.org/4237.html">
         <img src="http://dataunion.org/wp-content/uploads/2014/12/t0132c47f370ab8e384_副本.png"/>
        </a>
        <a class="link" href="http://dataunion.org/4237.html" rel="bookmark" title="机器学习经典算法详解及Python实现–K近邻(KNN)算法">
         机器学习经典算法详解及Python实现–K近邻(KNN)算法
        </a>
       </li>
       <li>
        <a href="http://dataunion.org/24220.html">
         <img src="http://dataunion.org/wp-content/uploads/2016/05/100910rrxp5plglxk4lcle-291x200.png"/>
        </a>
        <a class="link" href="http://dataunion.org/24220.html" rel="bookmark" title="520大数据：八成男性期待被表白 “套路”也是爱">
         520大数据：八成男性期待被表白 “套路”也是爱
        </a>
       </li>
       <li>
        <a href="http://dataunion.org/23785.html">
         <img src="http://dataunion.org/wp-content/uploads/2016/04/u7145986293872240263fm21gp0-298x200.jpg"/>
        </a>
        <a class="link" href="http://dataunion.org/23785.html" rel="bookmark" title="Docker安全基准：22项新增要点概述">
         Docker安全基准：22项新增要点概述
        </a>
       </li>
      </ul>
     </div>
     <!--相关文章-->
     <div class="comment" id="comments">
      <!-- You can start editing here. -->
      <!-- If comments are open, but there are no comments. -->
      <div class="title">
       期待你一针见血的评论，Come on！
      </div>
      <div id="respond">
       <p>
        不用想啦，马上
        <a href="http://dataunion.org/wp-login.php?redirect_to=http%3A%2F%2Fdataunion.org%2F16445.html">
         "登录"
        </a>
        发表自已的想法.
       </p>
      </div>
     </div>
     <!-- .nav-single -->
    </div>
    <!--Container End-->
    <aside id="sitebar">
     <div class="sitebar_list2">
      <div class="wptag">
       <span class="tagtitle">
        热门标签+
       </span>
       <div class="tagg">
        <ul class="menu" id="menu-%e5%8f%8b%e6%83%85%e9%93%be%e6%8e%a5">
         <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-1605" id="menu-item-1605">
          <a href="http://taidizh.com/">
           泰迪智慧
          </a>
         </li>
         <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-20884" id="menu-item-20884">
          <a href="http://www.transwarp.cn/">
           星环科技
          </a>
         </li>
         <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-3538" id="menu-item-3538">
          <a href="http://datall.org/">
           珈和遥感
          </a>
         </li>
         <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-20888" id="menu-item-20888">
          <a href="http://www.chinahadoop.cn/">
           小象学院
          </a>
         </li>
        </ul>
       </div>
      </div>
     </div>
     <div class="sitebar_list">
      <div class="textwidget">
       <div align="center">
        <a href="http://study.163.com/course/courseMain.htm?courseId=991022" target="_blank">
         <img src="http://dataunion.org/wp-content/uploads/2016/03/dv.jpg"/>
        </a>
       </div>
      </div>
     </div>
     <div class="sitebar_list">
      <h4 class="sitebar_title">
       文章分类
      </h4>
      <div class="tagcloud">
       <a class="tag-link-44" href="http://dataunion.org/category/industry/demo" style="font-size: 10.204724409449pt;" title="4个话题">
        Demo展示
       </a>
       <a class="tag-link-31" href="http://dataunion.org/category/experts" style="font-size: 15.826771653543pt;" title="52个话题">
        专家团队
       </a>
       <a class="tag-link-870" href="http://dataunion.org/category/tech/ai" style="font-size: 19.795275590551pt;" title="273个话题">
        人工智能
       </a>
       <a class="tag-link-488" href="http://dataunion.org/category/%e5%8a%a0%e5%85%a5%e6%95%b0%e7%9b%9f" style="font-size: 8pt;" title="1个话题">
        加入数盟
       </a>
       <a class="tag-link-869" href="http://dataunion.org/category/tech/viz" style="font-size: 17.204724409449pt;" title="93个话题">
        可视化
       </a>
       <a class="tag-link-30" href="http://dataunion.org/category/partners" style="font-size: 10.645669291339pt;" title="5个话题">
        合作伙伴
       </a>
       <a class="tag-link-889" href="http://dataunion.org/category/parterc" style="font-size: 11.582677165354pt;" title="8个话题">
        合作会议
       </a>
       <a class="tag-link-104" href="http://dataunion.org/category/books" style="font-size: 12.96062992126pt;" title="15个话题">
        图书
       </a>
       <a class="tag-link-220" href="http://dataunion.org/category/tech/base" style="font-size: 19.850393700787pt;" title="281个话题">
        基础架构
       </a>
       <a class="tag-link-219" href="http://dataunion.org/category/tech/analysis" style="font-size: 19.409448818898pt;" title="232个话题">
        数据分析
       </a>
       <a class="tag-link-887" href="http://dataunion.org/category/tech/dm" style="font-size: 13.291338582677pt;" title="17个话题">
        数据挖掘
       </a>
       <a class="tag-link-34" href="http://dataunion.org/category/tech" style="font-size: 20.732283464567pt;" title="404个话题">
        文章
       </a>
       <a class="tag-link-1" href="http://dataunion.org/category/uncategorized" style="font-size: 22pt;" title="693个话题">
        未分类
       </a>
       <a class="tag-link-4" href="http://dataunion.org/category/events" style="font-size: 14.503937007874pt;" title="29个话题">
        活动
       </a>
       <a class="tag-link-890" href="http://dataunion.org/category/tech/%e6%b7%b1%e5%ba%a6%e5%ad%a6%e4%b9%a0" style="font-size: 10.204724409449pt;" title="4个话题">
        深度学习
       </a>
       <a class="tag-link-221" href="http://dataunion.org/category/tech/devl" style="font-size: 18.968503937008pt;" title="193个话题">
        编程语言
       </a>
       <a class="tag-link-888" href="http://dataunion.org/category/career" style="font-size: 15.661417322835pt;" title="48个话题">
        职业规划
       </a>
       <a class="tag-link-5" href="http://dataunion.org/category/jobs" style="font-size: 14.11811023622pt;" title="25个话题">
        职位
       </a>
       <a class="tag-link-871" href="http://dataunion.org/category/industry" style="font-size: 15.716535433071pt;" title="49个话题">
        行业
       </a>
       <a class="tag-link-613" href="http://dataunion.org/category/industry/case" style="font-size: 16.984251968504pt;" title="84个话题">
        行业应用
       </a>
       <a class="tag-link-885" href="http://dataunion.org/category/industry/news" style="font-size: 17.425196850394pt;" title="102个话题">
        行业资讯
       </a>
       <a class="tag-link-10" href="http://dataunion.org/category/training" style="font-size: 14.228346456693pt;" title="26个话题">
        课程
       </a>
       <a class="tag-link-16" href="http://dataunion.org/category/sources" style="font-size: 15.661417322835pt;" title="48个话题">
        资源
       </a>
      </div>
     </div>
     <div class="sitebar_list">
      <h4 class="sitebar_title">
       功能
      </h4>
      <ul>
       <li>
        <a href="http://dataunion.org/wp-login.php?action=register">
         注册
        </a>
       </li>
       <li>
        <a href="http://dataunion.org/wp-login.php">
         登录
        </a>
       </li>
       <li>
        <a href="http://dataunion.org/feed">
         文章
         <abbr title="Really Simple Syndication">
          RSS
         </abbr>
        </a>
       </li>
       <li>
        <a href="http://dataunion.org/comments/feed">
         评论
         <abbr title="Really Simple Syndication">
          RSS
         </abbr>
        </a>
       </li>
       <li>
        <a href="https://cn.wordpress.org/" title="基于WordPress，一个优美、先进的个人信息发布平台。">
         WordPress.org
        </a>
       </li>
      </ul>
     </div>
    </aside>
    <div class="clear">
    </div>
   </div>
   <!--main-->
   ﻿
   <footer id="dibu">
    <div class="about">
     <div class="right">
      <ul class="menu" id="menu-%e5%ba%95%e9%83%a8%e8%8f%9c%e5%8d%95">
       <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-18024" id="menu-item-18024">
        <a href="http://dataunion.org/category/partners">
         合作伙伴
        </a>
       </li>
       <li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-20881" id="menu-item-20881">
        <a href="http://dataunion.org/contribute">
         文章投稿
        </a>
       </li>
       <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-20872" id="menu-item-20872">
        <a href="http://dataunion.org/category/%e5%8a%a0%e5%85%a5%e6%95%b0%e7%9b%9f">
         加入数盟
        </a>
       </li>
       <li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-22441" id="menu-item-22441">
        <a href="http://dataunion.org/f-links">
         友情链接
        </a>
       </li>
       <li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-20874" id="menu-item-20874">
        <a href="http://dataunion.org/aboutus">
         关于数盟
        </a>
       </li>
      </ul>
      <p class="banquan">
       数盟社区        ，
        做最棒的数据科学社区
      </p>
     </div>
     <div class="left">
      <ul class="bottomlist">
       <li>
        <a href="http://weibo.com/DataScientistUnion  " target="_blank" 　title="">
         <img src="http://dataunion.org/wp-content/themes/yzipi/images/weibo.png"/>
        </a>
       </li>
       <li>
        <a class="cd-popup-trigger" href="http://dataunion.org/16445.html#0">
         <img src="http://dataunion.org/wp-content/themes/yzipi/images/weixin.png"/>
        </a>
       </li>
      </ul>
      <div class="cd-popup">
       <div class="cd-popup-container">
        <h1>
         扫描二维码,加微信公众号
        </h1>
        <img src="http://dataunion.org/wp-content/themes/yzipi/images/2014-12-06-1515289049.png"/>
        <a class="cd-popup-close" href="http://dataunion.org/16445.html">
        </a>
       </div>
       <!-- cd-popup-container -->
      </div>
      <!-- cd-popup -->
     </div>
    </div>
    <!--about-->
    <div class="bottom">
     <a href="http://dataunion.org/">
      数盟社区
     </a>
     <a href="http://www.miitbeian.gov.cn/" rel="external nofollow" target="_blank">
      京ICP备14026740号
     </a>
     联系我们：
     <a href="mailto:contact@dataunion.org" target="_blank">
      contact@dataunion.org
     </a>
     <div class="tongji">
     </div>
     <!--bottom-->
     <div class="scroll" id="scroll" style="display:none;">
      ︿
     </div>
    </div>
   </footer>
   <!--dibu-->
  </div>
 </body>
</html>